package com.example.nutritionmate.controller;

import com.example.nutritionmate.dto.OCRResultDTO;
import com.example.nutritionmate.dto.OCRResultItemDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/result")
public class ResultController {
    @GetMapping("/test")
    public ResponseEntity<?> getTestResult(@AuthenticationPrincipal UserDetails userDetails) {
        try {
            // 模拟延迟2秒
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // 恢复中断状态
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("内部错误：线程中断");
        }
        OCRResultDTO resultDTO = new OCRResultDTO();
        resultDTO.getResults().add(new OCRResultItemDTO(1,"热量", "kcal", 164.0, true, null));
        resultDTO.getResults().add(new OCRResultItemDTO(2,"蛋白质", "g", 4.6, true, null));
        resultDTO.getResults().add(new OCRResultItemDTO(3,"脂肪", "g", 13.7, true, null));
        resultDTO.getResults().add(new OCRResultItemDTO(4,"碳水化合物", "g", 5.8, true, null));
        resultDTO.getResults().add(new OCRResultItemDTO(5,"钠", "mg", 2.0, true, null));
//        resultDTO.getResults().add(new OCRResultItemDTO(17,"维生素D", "mg", 15.0, false, "酰胺酸"));
        resultDTO.setWeight(25);
        return ResponseEntity.ok(resultDTO);
    }
}
